package #(package.Controller);
#set(lowerServerName = StrUtil.lowerFirst(table.serviceImplName))
#set(RqsDto = entity + 'RqsDto')
#set(rqsDto = StrUtil.lowerFirst(RqsDto))
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Date;
#if(!restControllerStyle)
import com.interheart.framecore.dto.PageRqsDto;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
#end
import #(package.ServiceImpl).#(table.serviceImplName);
import org.springframework.web.bind.annotation.RequestMapping;
import #(package.Entity).#(entity);
#if(restControllerStyle)
import com.interheart.framecore.dto.ResultDto;
import com.interheart.framecore.util.ResultDtoUtil;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestBody;
import #(package.Controller).validator.dto.#(RqsDto);
#else
import org.springframework.stereotype.Controller;
#end
#if(superControllerClassPackage)
import #(superControllerClassPackage);
#end

/**
 * @menu #(table.comment??)
 * @author #(author)
 * @date  #(date)
 */
#if(restControllerStyle)
@RestController
#else
@Controller
#end
@RequestMapping("#if(package.ModuleName)/#(package.ModuleName)#end/#if(controllerMappingHyphenStyle)#(controllerMappingHyphen)#else#(table.entityPath)#end")
#if(kotlin)
class #(table.controllerName)#if(superControllerClass) : #(superControllerClass)()#end

#else
#if(superControllerClass)
public class #(table.controllerName) extends #(superControllerClass) {
#else
public class #(table.controllerName) {
#end

    @Autowired
    #(table.serviceImplName) #(lowerServerName);

    #if(!restControllerStyle)
    /**
     * 分页列表
     * @author SHIKAI
     * @date #(date)
     * @status done
     */
    @RequestMapping("/list")
    public String list(PageRqsDto pageRqsDto, #(entity) #(table.entityPath), Model model){
        model.addAttribute("#(table.entityPath)List", #(lowerServerName).list(pageRqsDto, #(table.entityPath)));
        model.addAttribute("query", #(table.entityPath));
        return "#(table.entityPath)/list";
    }
    /**
     * 详情
     * @author SHIKAI
     * @date #(date)
     * @status done
     */
    @RequestMapping({"/info", "/info/{id}"})
    public String info(@PathVariable(required = false) Integer id, Model model){
        if (id != null ) {
            model.addAttribute("#(table.entityPath)", #(lowerServerName).getById(id));
        }
        return "#(table.entityPath)/form";
    }

    /**
     * 保存
     * @author SHIKAI
     * @date #(date)
     * @status done
     */
    @RequestMapping("/save")
    @ResponseBody
    public ResultDto save(#(entity) #(table.entityPath)){
        #(table.entityPath).setGmtCreate(new Date());
        return ResultDtoUtil.success(#(lowerServerName).save(#(table.entityPath)));
    }

    /**
     * 更新
     * @author SHIKAI
     * @date #(date)
     * @status done
     */
    @RequestMapping("/update")
    @ResponseBody
    public ResultDto update(#(entity) #(table.entityPath)){
        #(table.entityPath).setGmtModified(new Date());
        return ResultDtoUtil.success(#(lowerServerName).updateById(#(table.entityPath)));
    }

    /**
     * 删除
     * @author SHIKAI
     * @date #(date)
     * @status done
     */
    @RequestMapping({"/del", "/del/{id}"})
    @ResponseBody
    public ResultDto del(@PathVariable(required = false) Integer id){
            return ResultDtoUtil.success(#(lowerServerName).removeById(id));
        }
}
    #else

        ### 这里是前后端分离的的模板
    /**
     * 分页列表
     * @author SHIKAI
     * @date #(date)
     * @param
     * @return
     * @status done
     */
    @RequestMapping("/list")
    public ResultDto list(@RequestBody #(RqsDto) #(rqsDto)){
        return ResultDtoUtil.success(#(lowerServerName).list(#(rqsDto)));
    }

    /**
     * 详情
     * @author SHIKAI
     * @date #(date)
     * @param
     * @return
     * @status done
     */
    @RequestMapping("/info")
    public ResultDto info(@RequestBody #(entity) #(table.entityPath)){
        return ResultDtoUtil.success(#(lowerServerName).getById(#(table.entityPath).getId()));
    }

    /**
     * 保存
     * @author SHIKAI
     * @date #(date)
     * @param
     * @return
     * @status done
     */
    @RequestMapping("/save")
    public ResultDto save(@RequestBody #(entity) #(table.entityPath)){
        #(table.entityPath).setGmtCreate(new Date());
        return ResultDtoUtil.success(#(lowerServerName).save(#(table.entityPath)));
    }

    /**
     * 更新
     * @author SHIKAI
     * @date #(date)
     * @param
     * @return
     * @status done
     */
    @RequestMapping("/update")
    public ResultDto update(@RequestBody #(entity) #(table.entityPath)){
        #(table.entityPath).setGmtModified(new Date());
        return ResultDtoUtil.success(#(lowerServerName).updateById(#(table.entityPath)));
    }

    /**
     * 删除
     * @author SHIKAI
     * @date #(date)
     * @param
     * @return
     * @status done
     */
    @RequestMapping("/del")
    public ResultDto del(@RequestBody #(entity) #(table.entityPath)){
        return ResultDtoUtil.success(#(lowerServerName).removeById(#(table.entityPath).getId()));
    }
}
    #end
#end
